Put a Button on a Form to Send a Customized Email

Description

This lesson demonstrates how you can use Action Script to send out a customized email message. The goal is to send an email message to a customer asking it to confirm that its correct address.

  1. Right-click the "customers" table on the Tables/Sets tab of the Control Panel and select Default Form.

    images/Customer_Default_Form.gif
  2. The first step is to create an "email template" that has the body of the message to send to the customer. Select Email from the Tools menu.

    • This brings up the Alpha Anywhere "Email Client".

      images/email_3.gif
    images/email_2.gif
  3. First you need to specify the email address of the recipient. However, you do not want to use an actual email address. Instead, you want to refer to the field in the customer records that contains the customer's email address. Click 'xy' to open the Expression Builder.

  4. Press F2 to open the Field Name list.

    images/email_4.gif
  5. Scroll down, select the "Email" field, and click Insert. The Expression Builder looks like this:

    images/email_5.gif
  6. Click OK to close the Expression Builder. Alpha Anywhere puts "=Email" in the To field.

    images/email_6.gif
    The = prefix tells Alpha Anywhere that the text that follows is to be treated as an expression.
  7. Next, fill in the Subject: field: "Confirming Your Mailing Address".

  8. Now create the body of the message. Click inside the message body portion of the email. Type "Dear " to start the message.

    images/email_7.gif
  9. Now you want to insert a field from the current record. Click the Insert Mail Merge Field button.

    images/email_9.gif
  10. The Insert Field dialog opens. Note that this is a modeless dialog. You can leave it open while you type your message.

    images/email_9.gif
  11. Click the "Firstname" field and then click the Insert Field button. Type in the rest of the message as shown below:

    images/email_10.gif
  12. Now you are ready to insert the customer address information. Select the "company" field.

  13. Make sure the Suppress line if blank? check box is checked. Picture

    images/email_11.gif
  14. Click the Insert Field button.

  15. Click the New Line button.

  16. Continue selecting fields and typing text in the message body until you screen looks like this:

    images/email_12.gif
  17. Now save the template. Click the Save button to save the script.

  18. You can save templates in text files, or in the current table's Library (where forms, reports, etc. are stored). Select the Alpha Anywhere Library option, and enter "ConfirmAddress" as the template name.

    images/email_13.gif
  19. Before closing the Email Editor, click the Preview button to see how your email will look.

  20. Now you are ready to put a button on the form. Click the Design button to switch the form to Design Mode. Picture

    images/Custom_Action_Script_1.gif
  21. Click the Button Object tool '-' on the Toolbox.

  22. Click and drag to draw a button just above the Email field.

  23. When you release the button, the Define Button dialog box appears.

    images/email_14.gif
  24. Specify the button Label and then use the Style drop-down box to select the style of button you want.

  25. Click Next >.

  26. The Embedded Action Script Editor appears.

    images/Embedded_Action_Script_Editor.gif
  27. Click Add New Action.

  28. Select the "Email" category and the "Send an email message" Action.

    images/Action_Email_Send_an_Email_Message.gif
  29. The Genie appears. When you send a message you can either use Alpha Anywhere's built in email client, or you can use your default email client (e.g. Outlook, Eudora etc.). If you choose the built-in Alpha Anywhere email client, you get more options (as you will see on the next screen). For the purpose of this lesson, please choose the "Alpha Anywhere built-in client".

    images/email_17.gif
  30. You can either specify the message header as Part of the Genie, or you can extract the header from a saved template. Check the Load message header from a saved email template check box.

    images/email_18.gif
    The "message header" is the address portion of the message, not the body.
  31. You can specify that Alpha Anywhere should prompt for the template name at runtime, or you can specify the template name now. Having Alpha Anywhere prompt at runtime is useful if you want the operator to be able to select one of several different email messages to send to the client. Enter "ConfirmAddress" as the Template name.

    images/email_19.gif
  32. Click Next > to move to the next Genie page.

    images/email_20.gif
  33. You also want to load the message body from a template, so check the Load message body from a saved email template check box.

    images/email_21.gif
  34. Finally, choose "Open Alpha Anywhere email client as a modal dialog box". Picture

    images/email_22.gif
  35. Click Next >

  36. Click Finish to close the Genie. Your screen should now look like this:

    images/email_23.gif
  37. Click Finish to close the Define Button Genie.

  38. Save the form.

  39. Run the form.

  40. Enter a valid email address in the Email field (your own would be a good idea). Your screen should look like this:

    images/email_24.gif
  41. Click the Send Email Confirmation button. The Alpha Anywhere email client pops up with all the correct information merged into the message header and body.

    images/email_25.gif
  42. Now click the Send button to send the email. as you can see, Action Scripting makes it very easy for you to create highly customized email components to your applications.

    When you send an email message using the Alpha Anywhere email client, the message is stored in the Alpha Anywhere email outbox. This is a table you can add to the current database.
  43. To do so, click the green '+' icon on the Control Panel toolbar and select the "A_EMAIL.DBF.DBF" table in the Alpha Anywhere program folder.

    Netmailer automates the sending of emails. However, Netmailer does not use the email templates created through the process described here.